//
//  QMyCouponCell.m
//  QoilPublic
//
//  Created by 杨凯 on 2017/3/24.
//  Copyright © 2017年 杨凯. All rights reserved.
//

#import "QMyCouponCell.h"
@interface QMyCouponCell ()
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *timeleftLayout;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *moneySignLayout;
@property (weak, nonatomic) IBOutlet UILabel *typeTitleLab;
@property (weak, nonatomic) IBOutlet UIImageView *selectImg;
@property (weak, nonatomic) IBOutlet UILabel *moneyLab;
@property (weak, nonatomic) IBOutlet UIImageView *moneySignImg;
@property (weak, nonatomic) IBOutlet UIImageView *discourtImg;
@property (weak, nonatomic) IBOutlet UILabel *subTitleLab;
@property (weak, nonatomic) IBOutlet UILabel *dateLab;
@property (weak, nonatomic) IBOutlet UILabel *titleLab;

@end

@implementation QMyCouponCell
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    if (iphone6Plus_5_5) {
        _timeleftLayout.constant = 141;
    }else if (iphone5x_4_0){
        _timeleftLayout.constant = 101;
        _moneySignLayout.constant = 3;
        //字体13
    }
}

- (void)setModel:(QCouponModel *)model{
    _model = model;
    
    if ([_model.couponMakeState isEqualToString:@"1"]||[_model.couponMakeState isEqualToString:@"4"]) {
        _moneySignImg.image = [UIImage imageNamed:@"Coupon_￥blue"];
        _discourtImg.image = [UIImage imageNamed:@"Coupon_discountBlue"];
        _moneyLab.textColor = [QColorUtility defaultBlueColor];
        _subTitleLab.textColor = [QColorUtility defaultBlueColor];
    }else{
        _moneySignImg.image = [UIImage imageNamed:@"Coupon_￥gray"];
        _discourtImg.image = [UIImage imageNamed:@"Coupon_discountGray"];
        _moneyLab.textColor = [QColorUtility defaultBackColor];
        _subTitleLab.textColor = [QColorUtility defaultBackColor];
    }
    
    if ([_model.cardType isEqualToString:@"1"]) {
        _typeTitleLab.text = [NSString stringWithFormat:@"现金券 · %@元",_model.cashDiscount];
        _moneyLab.text = _model.cashDiscount;
        _discourtImg.hidden = YES;
        _moneySignImg.hidden = NO;
    }else if ([_model.cardType isEqualToString:@"2"]){
        if (![_model.discount isEqualToString:@""]) {
            _typeTitleLab.text = [NSString stringWithFormat:@"折扣券 · %@折",_model.discount];
            _moneySignImg.hidden = YES;
            _discourtImg.hidden = NO;
            _moneyLab.text = [NSString stringWithFormat:@"%@",_model.discount];
        }
    }
    
    
    _subTitleLab.text = [NSString stringWithFormat:@"满￥%@可使用",_model.minUseCash];
    
    if (![_model.startTime isEqualToString:@""]&&![_model.endTime isEqualToString:@""]) {
        _dateLab.text = [NSString stringWithFormat:@"%@-%@",[[_model.startTime substringWithRange:NSMakeRange(0, 10)] stringByReplacingOccurrencesOfString:@"-" withString:@"."],[[_model.endTime substringWithRange:NSMakeRange(0, 10)] stringByReplacingOccurrencesOfString:@"-" withString:@"."]];

    }
    
    _titleLab.text = [NSString stringWithFormat:@"%@",_model.title];
    
    if (_model.hiden == YES) {
        _selectImg.hidden = NO;
        NSUserDefaults * user = [NSUserDefaults standardUserDefaults];
        NSString *code = [user objectForKey:@"cardCode"];
        if ([_model.cardCode isEqualToString:code]) {
            _selectImg.image = [UIImage imageNamed:@"payselect_image"];
        }else{
            _selectImg.image = [UIImage imageNamed:@"paynoselect_image"];

        }
    }else{
        _selectImg.hidden = YES;
    }
    
    
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
